<template>
  <div>
    <el-col :span="12">
      <el-card class="header layouts" style="height:200px;" shadow="always">
         <el-row class="title">任务进度</el-row>
         <el-row class="layouts_one">
          <div id="main2"></div>
         </el-row>
      </el-card>
    </el-col>
  </div>
</template>

<script>
  import * as echarts from 'echarts';
  export default {
    data() {
      return {
        datalist:[]
      }
    },
    created() {
       // 假如调用的接口 ====> 返回的数据
       var list = ["xiaoming","lisi","wangwu","lisai","nma","xiaoming","lisi","wangwu","lisai","nma","xiaoming","lisi","wangwu","lisai","nma"]
       this.datalist = list;
      },
    mounted() {
      const myChart2 = echarts.init(document.getElementById('main2'));
      // 第三个图标
      myChart2.setOption({
       xAxis: {
       type: 'category',
       data: this.datalist,
       axisLabel: {
         rotate: this.datalist.length > 10? 60 : 0
       }
    },
     yAxis: {
       type: 'value',
       min: 0,
       max: 4
     },
     grid: {
       top:'75px',
       containLabel: true
     },
     legend: {
       orient: 'horizontal',
       top:'230px'
     },
     tooltip: {
      trigger: 'axis',
       axisPointer: {
       type: 'shadow'
      }
    },
     series: [
       {
         name: '未完成任务',
         type: 'bar',
         data:  [1, 3, 0, 1, 2, 1, 2],
         itemStyle: {
           color: '#FFCCC7'
         },
         label: {
           show: true,
           position: 'top',
           color: '#FFCCC7'
         },
         barGap: 0,
         barWidth:18
       },
       {
         name: '已完成任务',
         type: 'bar',
         data:  [2, 4, 0, 2, 2, 2, 2],
         itemStyle: {
           color: '#93D2F3'
         },
         label: {
           show: true,
           position: 'top',
           color: '#93D2F3'
         },
         barGap: 0,
         barWidth:18
       }]
    })
  }
}
</script>

<style lang="less" scoped>
.header {
  margin-bottom:15px;
  padding: 20px;
  .title {
    font-weight: bolder;
    padding-left: 12px;
    border-left: 6px solid rgb(124, 148, 237);
  }
  .item {
    margin-top: 30px;
    width: 154px;
    height: 80px;
    margin-left: 22px;
    color: white;
    // background-color: pink;
    border-radius: 5px;
  }
  .item_li {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .item_li span:first-child {
      font-size: 24px;
      margin-top: 15px;
      margin-bottom: 5px;
      align-self: center;
    }

   .item_li span:last-child {
      display: flex;
      font-size: 16px;
    }
}

.layouts {
  margin-right: 15px;
  .layouts_one {
     display: flex;
     justify-content: center;
     align-items: center;
  }

}

/deep/ .el-col-4 {
  margin-right: 38px;
}

#main2 {
  height: 300px;
  width: 100%;
  margin-top: -60px;
}
</style>
